<style lang="scss"></style>
<template>
    <view>
        <view class="tabbar">
            <view v-for="(tab, index) in tabs" :key="index" class="item" :class="[tabSel === index ? 'active' : '']" @tap="selected(index)">
                <image class="img" :src="'/static/tab/tab_' + (tabSel === index ? tab.simgb : tab.simg) + '.png'" />
                <text>{{ tab.title }}</text>
            </view>
        </view>
        <view class="tab-content" v-show="tabSel === 0">
            <gs-job-list ref="zwlist" page="gs-home" @sxfilter="sxfilter"></gs-job-list>
            <block></block>
        </view>
        <block></block>
        <view class="tab-content" v-show="tabSel === 1">
            <gs-aunty-list ref="sqlist" page="gs-home" @sxfilter="sxfilter"></gs-aunty-list>
            <block></block>
        </view>

        <view v-if="tabSel === 2" class="tabc">
            <p-publish-category :delegate="2"></p-publish-category>
            <block></block>
        </view>
        <view v-if="tabSel === 3" class="tab-content">
            <p-profile :type="2" ref="profile"></p-profile>
            <block></block>
        </view>
        <!-- drawer -->
        <sxfilter ref="sxmodule" @reset="reset" @closeDrawer="closeDrawer"></sxfilter>
    </view>
</template>
<script>
import { cityType } from '../../api/api';
import pPublishCategory from '../c/p-publish-category';
import pProfile from '../c/p-profile.vue';
import gsJobList from './gs-job-list.vue';
import gsAuntyList from './gs-aunty-list.vue';
import tabs from '@/common/tabs-config.js';
import sxfilter from '../c/c-filter-drawer.vue';
export default {
    components: {
        pPublishCategory,
        pProfile,
        gsJobList,
        gsAuntyList,
        sxfilter
    },
    data() {
        return {
            tabs: tabs.gs,
            tabSel: 0,
            cityId: ''
        };
    },
    methods: {
        async selected(index) {
            this.tabSel = index;
            let tab = this.tabs[index];
            uni.setNavigationBarTitle({
                title: tab.title
            });
            uni.setNavigationBarColor({
                backgroundColor: index === 3 ? '#FE6b51' : '#FFFFFF',
                frontColor: '#000000'
            });
            if (this.tabSel === 0) {
                this.$refs.zwlist.show();
            } else if (this.tabSel === 1) {
                this.$refs.sqlist.show();
            }
        },
        async loadArea(param) {
            let res = await cityType(param);
            this.$global.districts = res || [];
            this.array1 = res;
            this.cityId = res[0].cityId;
            if (this.$refs.zwlist) {
                this.$refs.zwlist.refresh();
            }
            if (this.$refs.sqlist) {
                this.$refs.sqlist.refresh();
            }
        },
        // 关闭抽屉
        closeDrawer(e) {
            console.log(e, '关闭抽屉');
        },
        // 重置抽屉参数
        reset(e) {
            console.log(e, '重置抽屉参数');
        },
        // 点击筛选
        sxfilter(e) {
            console.log('点击筛选3');
            this.$refs.sxmodule.sxfilterfun(e);
        }
    },
    onLoad(e) {
        // #ifdef H5
        this.$global.sessionkey = "530970oUtyp5XJTdgNm8RsGRgkrlEVWD3Y";
        this.$global.role = 3;
        // #endif
        var that = this;
        this.loadArea({
            district: this.$global.district,
            adcode: this.$global.adcode
        });
        this.$getUserBasic()
    },
    onShareAppMessage(options) {
        var that = this; // 设置菜单中的转发按钮触发转发事件时的转发内容
        var shareObj = {
            title: '51好阿姨', // 默认是小程序的名称
            path: '/pages/login/loginpage', // 默认是当前页面，必须是以‘/’开头的完整路径
            imgUrl: '', //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径， //支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
            success(res) {
                // 转发成功之后的回调
                if (res.errMsg == 'shareAppMessage:ok') {
                }
            },
            fail() {
                // 转发失败之后的回调
                if (res.errMsg == 'shareAppMessage:fail cancel') {
                    // 用户取消转发
                } else if (res.errMsg == 'shareAppMessage:fail') {
                    // 转发失败，其中 detail message 为详细失败信息
                }
            },
            complete() {
                // 转发结束之后的回调（转发成不成功都会执行）
            }
        }; // 返回shareObj
        return shareObj;
    },
    onReachBottom() {
        let tab = this.tabs[this.tabSel];
        if (this.tabSel === 0 || this.tabSel === 1) {
            tab.page = tab.page + 1;
            let result = '';
            if (this.tabSel === 0) {
                this.$refs.zwlist.loadMore();
            } else if (this.tabSel == 1) {
                this.$refs.sqlist.loadMore();
            }
        }
    },
    onShow() {
        if (this.tabSel == 3) {
            console.log('refresh when onshow');
            this.$refs.profile.updateUI()
        }
    }
};
</script>
